<template>
  <div v-if="treeData.length > 0">
    <span style="color: rgba(0, 0, 0, 0.85);margin-right: 8px;">组织:</span>
    <a-tree-select v-model="checkVal" @change="checkChange" style="width: 200px;margin: 6px 10px 0 0;" :tree-data="treeData" :replaceFields="{ title: 'orgName', key: 'orgId', value: 'orgId' }" placeholder="选择组织" />
  </div>
</template>

<script>
import {
  orgGetMenuTree
} from '@/api/human/relationOrg'
export default {
  name: 'orgSelect',
  data() {
    return {
      title: "组织选择",
      visible: false,
      enterpriseId: "",
      submitLoading: false,

      treeData: [],
      checkVal: [],
    }
  },
  watch: {

  },
  methods: {
    add(id) {
      if (id) {
        this.checkVal = [];
        this.enterpriseId = id;
        this.initMenuTree(id)
      }
    },
    async initMenuTree(id) {
      const { code, data } = await orgGetMenuTree(id);
      if (code === '1') {
        this.treeData = data;
      }
    },
    reset() {
      this.checkVal = [];
    },
    checkChange(value, label) {
      let orgObj = {
        key: value
      }
      this.$emit('on-tree', orgObj)
    },
  }
}
</script>
